import http from "@/api";
import {
  AccountList,
  ResData,
  ResDetail,
  ResDict,
  ResPage,
  ResPassResult,
  ResultData,
  ResultTaskData,
  ResUser,
  VersionData
} from "@/api/interface";

export const getTodayDataApi = () => {
  return http.get<ResData>(`/today/data`);
};

export const getYesterdayDataApi = () => {
  return http.get<ResData>(`/yesterday/data`);
};

export const getAccountListApi = (params: Record<string, any>) => {
  return http.get<ResPage<AccountList>>(`/accountList`, params);
};

export const addPhoneApi = (params: Record<string, any>) => {
  return http.post<ResultData>(`/phone`, params);
};

export const deletePhoneApi = (ip: string) => {
  return http.delete(
    `/phone`,
    {},
    {
      data: JSON.stringify({ ip }),
      headers: {
        "Content-Type": "application/json"
      }
    }
  );
};

export const reconnectPhoneApi = (accountId: string) => {
  return http.post<ResultData>(`/phone/reconnect`, { accountId });
};

export const updateAccountGroupApi = (params: Record<string, any>) => {
  return http.put<ResultData>(`/account/group`, params);
};

export const addInfoListApi = () => {
  return http.get(`/addInfoList`);
};

export const startTaskApi = (params: Record<string, any>) => {
  return http.post<ResultData>(`/start/mm/task`, params);
};

export const pauseTaskApi = () => {
  return http.post<ResultData>(`/pause/mm/task`);
};

export const stopTaskApi = () => {
  return http.post<ResultData>(`/stop/mm/task`);
};

export const startWeTaskApi = (params: Record<string, any>) => {
  return http.post<ResultData>(`/start/wework/task`, params);
};

export const pauseWeTaskApi = () => {
  return http.post<ResultData>(`/pause/wework/task`);
};

export const stopWeTaskApi = () => {
  return http.post<ResultData>(`/stop/wework/task`);
};

export const getPhoneUrlApi = (accountId: string) => {
  return http.get<ResultData>(`/phone/url?accountId=${accountId}`);
};

export const refreshPhoneApi = (accountId: string) => {
  return http.get<ResultData>(`/phone/refresh/control?accountId=${accountId}`, {}, { loading: false });
};

export const getTaskDetailApi = () => {
  return http.get<ResDetail>(`/mm/task/detail`);
};

export const getWeTaskDetailApi = () => {
  return http.get<ResDetail>(`/wework/task/detail`);
};

export const getResultApi = (page: number, size: number) => {
  return http.get<{ result: boolean; total: number; resultList: Record<string, any>[] }>(`/result?&page=${page}&size=${size}`);
};

export const downloadResultApi = (result_id: string) => {
  return http.get(`/download/result?result_id=${result_id}`, {}, { responseType: "blob" });
};

export const readMessageApi = (params: Record<string, any>) => {
  return http.post<ResultData>(`/read/message`, params);
};

export const getAccountPassApi = (account_id: string, page: number, size: number) => {
  return http.get<ResPassResult>(`/account/friend/pass?account_id=${account_id}&page=${page}&size=${size}`);
};

export const getUserListApi = () => {
  return http.get<ResUser>(`/user/list`);
};

export const getAccountTypesApi = () => {
  return http.get<ResDict>(`/account/types`);
};

export const getAccountGroupsApi = () => {
  return http.get<ResDict>(`/account/groups`);
};

export const getAccountStatesApi = () => {
  return http.get<ResDict>(`/account/states`);
};

export const registerUserApi = (params: any) => {
  return http.post<ResultData>(`/register`, params);
};

export const deleteUserApi = (username: string) => {
  return http.delete(`/user`, { username });
};

export const changePasswordApi = (params: any) => {
  return http.post<ResultData>(`/change/password`, params);
};

export const resetPasswordApi = (params: any) => {
  return http.post<ResultData>(`/reset/password`, params);
};

export const getBrowseResultApi = (page: number, size: number) => {
  return http.get<{ result: boolean; total: number; resultList: Record<string, any>[] }>(
    `/browse/result?&page=${page}&size=${size}`
  );
};

export const downloadBrowseResultApi = (result_id: string) => {
  return http.get(`/download/browse/result?result_id=${result_id}`, {}, { responseType: "blob" });
};

export const getAccountSortTypesApi = () => {
  return http.get<ResDict>(`/account/sortTypes`);
};

export const startVideoTaskApi = (params: Record<string, any>) => {
  return http.post<ResultData>(`/start/mm/video/task`, params);
};

export const stopVideoTaskApi = () => {
  return http.post<ResultData>(`/stop/mm/video/task`);
};

export const videoTaskStateApi = () => {
  return http.get<ResultTaskData>(`/video/task/state`);
};

export const startLookTaskApi = (params: Record<string, any>) => {
  return http.post<ResultData>(`/start/mm/look/task`, params);
};

export const stopLookTaskApi = () => {
  return http.post<ResultData>(`/stop/mm/look/task`);
};

export const lookTaskStateApi = () => {
  return http.get<ResultTaskData>(`/look/task/state`);
};

export const versionApi = () => {
  return http.get<VersionData>(`/mm/version`);
};
